package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
	"time"
)

type qq struct {
	qqNum  int
	qqPass string
}

func main() {

	count := 84331445

	allstrs := make([]qq, count) //初始化数组
	path := "D:\\golang\\QQ.txt"
	qqfile, _ := os.Open(path) //打开文件
	defer qqfile.Close()       // 延迟关闭

	bf := bufio.NewReader(qqfile) // 读取数据
	i := 0

	for {
		line, _, err := bf.ReadLine() //读取一样文件

		if err == io.EOF { //读取到文件的最后一样
			break
		}

		linestr := string(line) //转化成字符串
		arrStr := strings.Split(linestr, "----")
		if len(arrStr) == 2 {
			allstrs[i].qqNum, _ = strconv.Atoi(arrStr[0])
			allstrs[i].qqPass = arrStr[1]
		}

		i++
	}
	fmt.Println("数据载入内存")
	time.Sleep(time.Second * 10)

	for {
		fmt.Println("请输入要查询的数据")
		var inputstr int
		fmt.Scanln(&inputstr)

		starttime := time.Now() //时间开始
		for j := 0; j < count; j++ {

			if allstrs[j].qqNum == inputstr { //字符串搜索
				fmt.Println(j, allstrs[j].qqNum, allstrs[j].qqPass)
				break
			}
		}
		fmt.Println("一共用了", time.Since(starttime))
	}

}
